package com.guigu.buy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.buy.pojo.Stock;
import com.guigu.buy.mapper.StockMapper;
import com.guigu.buy.service.IStockService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.buy.vo.StockVo;
import com.guigu.buy.vo.Stock_UnAudit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@Service
public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements IStockService {
    @Autowired
    private StockMapper stockMapper;


    public PageInfo<Stock> queryAll(int pageNo, int pageSize, StockVo vo) {
        QueryWrapper wrapper=new QueryWrapper();
        if(!StringUtils.isEmpty(vo.getStockName())){
            wrapper.eq("stock_name",vo.getStockName());
        }
        if(vo.getStockType()!=null ){
            wrapper.eq("stock_type",vo.getStockType());
        }
        wrapper.eq("check_tag","S001-1");
        List<Stock> list=this.list(wrapper);
        PageHelper.startPage( pageSize,pageNo);
        PageInfo<Stock> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<Stock> unAudit(int pageNo, int pageSize, Stock_UnAudit vo) {
        QueryWrapper wrapper=new QueryWrapper();
        if(!StringUtils.isEmpty(vo.getStockName())){
            wrapper.eq("stock_name",vo.getStockName());
        }
        if(vo.getStockType()!=null && vo.getStockName()!=""){
            wrapper.eq("stock_type",vo.getStockType());
        }
        if(!StringUtils.isEmpty(vo.getCheckTag())){
            wrapper.eq("check_tag",vo.getCheckTag());
        }else {
            wrapper.eq("check_tag","S001-0");
        }
        List<Stock> list=this.list(wrapper);
        PageHelper.startPage(pageSize,pageNo);
        PageInfo<Stock> pageInfo=new PageInfo<Stock>(list);
        return pageInfo;
    }
}
